package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Case;
import com.woniuxy.entity.Doctor;
import com.woniuxy.mapper.CaseMapper;
import com.woniuxy.service.ICaseService;
import com.woniuxy.service.IDoctorService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.CONSTANT;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author：xurice
 * @date：Created in 2024/4/15 19:11
 * @description：
 * @modified By：
 * @version: $
 */
@Service
public class CaseServiceImpl implements ICaseService, SaasService {
    @Autowired
    CaseMapper caseMapper;
    @Autowired
    IDoctorService doctorService;

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public ResponseData<?> addPatientRecord(Case patientRecord) {
        Doctor doctor = (Doctor) doctorService.queryDoctor().getData();
        if (doctor.getDocPtId().equals(CONSTANT.IS_OUTPATIENT)) {
            patientRecord.setCiType("0");//门诊医生 开的病历 0
        }else {
            patientRecord.setCiType("1");//住院医生 开的病历 1
        }
        caseMapper.addPatientRecord(patientRecord);
        return new ResponseData<>().ok();
    }

    //查询病历
    @SneakyThrows
    @Override
    public ResponseData<?> selectCase(PageParam<Case> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        List<Case> cases = caseMapper.selectCase(pageParam.getParam().getCiCaseId());
        PageInfo<Case> pageInfo = new PageInfo<>(cases);
        return new ResponseData<>().ok(pageInfo);
    }
}
